function addpic()
{
    //alert(pixbox);

    var pic=$("#picbox2 .control-group").length;
    pic++;
    var newpic="<div class=\"control-group\">商品编码<input id=\"zpic" +pic+"\" onblur=\"psize(this)\" class=\"input-box\" type=\"text\" autocomplete=\"off\" name=\"show_height\"" + " value=\"\">数量<input" + " value=\"1\" id=\"spsl" +pic+"\"></div>" + " </div>";
    if(pic<=12){
        $("#picbox2").append(newpic);
    }else{
        alert("个人建议不要超过十二个！");
    }
}
function delpic()
{
    var pic=$("#picbox2 .control-group").length;
    pic--;
    if(pic>=1){
        $("#picbox2 .control-group").eq(pic).remove();
    }else{
        alert("亲再删就没有了啊！！！！");
    }
}
function psize(obj){
    var sSrc = obj.value;
    if(IsURL(sSrc)){
        $("<img/>").attr("src", sSrc).load(function() {
            imgWidth = this.width;
            imgHeight = this.height;
            $("#show_height").val(imgHeight);
            $("#show_width").val(imgWidth);
        });
    }
}
function GetForm(id)
{
    var value=$("#"+id).val();
    return value;
}

function getpicdata(){

    var cdata = "";
    var ccon = $("#picbox2 .control-group").length;
    for (var i = 1; i <= ccon; i++) {
        cdata += GetForm("zpic" + i) + "#p2#" + GetForm("rpic" + i) + "#p2#" + GetForm("link" + i);
        if (i != ccon) {
            cdata += "#p1#";
        }
    }
    return cdata;
}
function send(gettype)
{
    if(!check()){
        return false;
    }
    $("#load").html("<img style='vertical-align: middle;' src='./images/loading.gif'/>");
    var opentype = $(":radio[name='opentype']:checked").val();
    var shoptype = $(":radio[name='shoptype']:checked").val();
    var flashtime = GetForm("flashtime");
    var flashtype = GetForm("flashtype");
    var modmargin = GetForm("modmargin");
    var ajaxdata = ""
    var picdata=getpicdata();

    ajaxdata += "gettype="+gettype+"&shoptype="+shoptype+"&flashtype="+flashtype+"&flashtime="+flashtime+"&opentype="+opentype+"&modmargin="+modmargin+"&picdata="+encodeURIComponent(picdata);

    if(gettype==0) {
        $("#ifm").attr("src","./index.php?get=active&getmod=hover&ajax=1&"+ajaxdata);
        setTimeout(function () {
            $("#load").html("");
        }, 2000);
    }
    else {
        $.ajax({
            type: "post",
            url : "./index.php?get=active&getmod=hover&ajax=1",
            dataType:'html',
            data: ajaxdata,
            success: function(html){
                $(".getcode").css("display","block");
                $("#load").html("");
                $("#codebox").val(html);
                if($(".zclip").length > 0 ){
                    //没得任何活动
                }else{
                    $('#copy_input').zclip({
                        path: 'js/ZeroClipboard.swf',
                        copy: function(){
                            return $('#codebox').val();
                        },
                        afterCopy: function(){
                            alert("复制成功！");
                            $("#codebox").css("background-color",'#cff');
                        }
                    });
                }
            }
        });
    }
}

function check(){
    var pics = $("#picbox2 .control-group").length;
    for (var i=1;i<=pics;i++)
    {
        var url = $("#zpic"+i).val();
        if(url==""){
            $("#zpic"+i).focus();
            alert("注意：图片地址 "+i+" 尚未填写，还不能生成代码哦！");
            return (false);
        }else{
            if(IsURL(url)== true){
                if(i==pics){
                    return (true);
                }
            }else{
                alert("图片地址似乎没对哦！");
                $("#zpic"+i).focus();
                return (false);
            }
        }
    }
}
function IsURL(bgurl) {
    var strRegex = "((^http)|(^https)|(^ftp)):\/\/(\\w)+\.(\\w)+";
    var re = new RegExp(strRegex);
    if (re.test(bgurl)){
        return true;
    } else {
        return false;
    }
}/**
 * Created by Linmens on 15/11/10.
 */
